

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head><meta name="robots" content="index,follow" />
<meta name="keywords" content="Software Development" />
<meta name="GENERATOR" content="Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)" />
<link rel="pingback" href="http://blogs.msdn.com/b/the1/pingback.aspx" />
<link href="http://i1.blogs.msdn.com/rrcontent/7632fe1dd91290a46b3a118f9478cf1b-27cae0dd5641775697cb89e9a8587625-RequestReducedStyle.css" rel="Stylesheet" type="text/css" /><link rel="alternate" type="application/rss+xml" title="Site Home (RSS 2.0)" href="http://blogs.msdn.com/rss.aspx"  />
<link rel="alternate" type="application/rss+xml" title="the1&#39;s Comments (RSS 2.0)" href="/members/the1/comments/rss.aspx"  />
<link rel="alternate" type="application/rss+xml" title="the1&#39;s Activities (RSS 2.0)" href="/members/the1/activities/rss.aspx"  />
<link rel="alternate" type="application/rss+xml" title="Activities of People the1 Follows (RSS 2.0)" href="/members/the1/activities/followersrss.aspx"  />
<link rel="alternate" type="application/rss+xml" title="the1&#39;s Groups Activities (RSS 2.0)" href="/members/the1/activities/groupsrss.aspx"  />
<link rel="alternate" type="application/rss+xml" title="the1&#39;s WebLog (RSS 2.0)" href="http://blogs.msdn.com/b/the1/rss.aspx"  />
<link rel="alternate" type="application/atom+xml" title="the1&#39;s WebLog (Atom 1.0)" href="http://blogs.msdn.com/b/the1/atom.aspx"  />
<link rel="alternate" type="application/rss+xml" title="the1&#39;s WebLog - All Comments (RSS 2.0)" href="http://blogs.msdn.com/b/the1/rsscomments.aspx"  />
<link rel="alternate" type="application/rss+xml" title="How Would You Get the Count of an Array in C++? - Comments for this post (RSS 2.0)" href="http://blogs.msdn.com/b/the1/rsscomments.aspx?WeblogPostID=128242"  />

                    
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
          <link rel="shortcut icon" type="image/ico" href="/themes/MSDN2/favicon.ico" />
          <!--
            Third party scripts and code linked to or referenced from this website are licensed to you by the parties that own such code, not by Microsoft.  See ASP.NET Ajax CDN Terms of Use – http://www.asp.net/ajaxlibrary/CDN.ashx.
          -->
          <link href="http://i1.blogs.msdn.com/rrcontent/6e455ee01481483d5d047db51a775dad-ffc9f7e1f0412800af51bef62a866f63-RequestReducedStyle.css" rel="Stylesheet" type="text/css" /><script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.2.min.js" type="text/javascript" language="javascript"></script>
                            
          <link type="text/css" rel="stylesheet" href="/themes/MSDN2/css/DynamicStyle.aspx?PreviewKey=0" media="screen,print" />
          <link type="text/css" rel="stylesheet" href="/themes/blogs/MSDN2/css/DynamicStyle.aspx?WeblogID=3405&PreviewKey=0" media="screen,print" />
        
          <!--[if lte IE 6]>
              <link type="text/css" rel="stylesheet" href="/themes/MSDN2/css/ie6.css" media="screen,print" />
          <![endif]-->
                  <meta name="msvalidate.01" content="B717AD6FC29D3A844832AF011B5F9E4C" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://blogs.msdn.com/b/the1/rsd.ashx" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" title="WLWManifest" href="http://blogs.msdn.com/b/the1/wlwmanifest.ashx" />

        <!--
            Third party scripts and code linked to or referenced from this website are licensed to you by the parties that own such code, not by Microsoft.  See ASP.NET Ajax CDN Terms of Use – http://www.asp.net/ajaxlibrary/CDN.ashx.
          -->
        <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.2.min.js" type="text/javascript" language="javascript"></script>
    <title>
	How Would You Get the Count of an Array in C++? - the1's WebLog - Site Home - MSDN Blogs
</title></head>
	<body spellcheck="true">
		<form name="aspnetForm" method="post" action="/b/the1/archive/2004/05/07/128242.aspx" id="aspnetForm">
<div>
<input type="hidden" name="ctl00_content_ctl00_w_52320__af8d15_ctl00_ctl00_PlaceHolder1_ctl04_bpCommentForm_ctl04_invisibleCaptcha_answer" id="ctl00_content_ctl00_w_52320__af8d15_ctl00_ctl00_PlaceHolder1_ctl04_bpCommentForm_ctl04_invisibleCaptcha_answer" value="" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTM5OTAxNDYyNWRkvI787cXLvh9XHlDReEjVejxzcZ4=" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="http://i1.blogs.msdn.com/rrcontent/202a7903c2e01f24065b9cd260bcb433-44d65c30df3417889f8fe7bb24eb3ee5-RequestReducedScript.js" type="text/javascript" ></script>


<div>

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="84C00179" />
</div>
			
            
                
            
            <div class="header-fragments-header"></div>
<div class="header-fragments"><div class="header-fragment-outer top-bar msdn-header-fragment-outer msdn-top-bar"><div class="header-fragment-inner top-bar msdn-header-fragment-inner msdn-top-bar"><div class="header-fragment welcome-message" id="header-fragment-1402503690">


<!-- always render -->
</div><div class="header-fragment login-logout" id="header-fragment-1402503691">





        <div class="navigation-list-header"></div>
        <ul class="navigation-list">

            <li class="navigation-item">
                <span id="ctl00_header_fragment_1402503691__af8d15_ctl00_ctl02_ctl05_WLIDLoginButton1" class="internal-link live-id-button"><a href="https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=12&ct=1421813167&rver=6.0.5286.0&wp=MBI&wreply=http:%2F%2Fblogs.msdn.com%2Fb%2Fthe1%2Farchive%2F2004%2F05%2F07%2F128242.aspx&lc=1033&id=271611">Sign in</a></span>
            </li>
        </ul>
        <div class="navigation-list-footer"></div>
    </div><div class="header-fragment user-welcome-without-login" id="header-fragment-1402503692">

 &nbsp;<!-- always render -->

</div></div></div><div class="header-fragment blog-banner" id="header-fragment-1402503693">



<div class="site-banner blog-banner">

<h1 class="blog-banner-name"><a href="/b/the1/">the1's WebLog</a></h1>

</div>

</div></div>
<div class="header-fragments-footer"></div>
			
    <div class="content-fragment-page post" id="ctl00_content_ctl00_page"><div class="layout">
<div class="layout-header"></div>
<div class="layout-content content-left-sidebar-right" id="ctl00_content_ctl00_layout">
<div class="layout-region right-sidebar" id="ctl00_content_ctl00_right-sidebar">
<div class="layout-region-inner right-sidebar"><div class="content-fragment c-t-f-widget no-wrapper-with-spacing with-header" id="fragment-52310">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-header"><div>Translate This Page</div></div>
<div class="content-fragment-content">


     <!--
         
           localize text, such as translate this & powered by 
           
           
            -->
<div id="MicrosoftTranslatorWidget" style="width: 275px; min-height: 83px;
    border-color: #333333; background-color: #CCCCCC;">
    <noscript>
        <a href="http://www.microsofttranslator.com/bv.aspx?a=http%3a%2f%2fblogs.msdn.com%2f">Translate this
            page</a><br />
        Powered by <a href="http://www.microsofttranslator.com">Microsoft® Translator</a>
    </noscript>
    <script type="text/javascript">
        setTimeout(function () {
            var s = document.createElement("script");
            s.type = "text/javascript";
            s.charset = "UTF-8";
            s.src = "http://www.microsofttranslator.com/Ajax/V2/Widget.aspx?siteData=ncUzpG6DNC3ChU0huEHZCFQbqrzCQRcTVqXdHso8P2KRGM-oFXjoeYwum3D31voFEyqUPj4HjacfvEdrHEyIG8CuATkNhQmRwcZkpGVFjvVnLd1gzFP2dxWEWKdcQtE1&mode=manual&from=en-us&layout=ts";
            var p = document.getElementsByTagName('head')[0] || document.documentElement; p.insertBefore(s, p.firstChild);
        }, 0); 
    </script>
</div>
</div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment blog-links no-wrapper-with-spacing with-header" id="fragment-52311">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-header"><div>Options</div></div>
<div class="content-fragment-content">

		<div class="navigation-list-header"></div>
		<ul class="navigation-list">
	<li class="navigation-item"><a class="internal-link view-application" href="/b/the1/"><span></span>Blog Home</a></li><li class="navigation-item"><a class="internal-link view-contact" href="/b/the1/contact.aspx"><span></span>Email Blog Author</a></li><li class="navigation-item"><a class="internal-link email-post" href="mailto:?subject=How Would You Get the Count of an Array in C++?&amp;body=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx">
		<span></span>Share this
	</a></li><li class="navigation-item"><a class="internal-link rss" href="/b/the1/rss.aspx"><span></span>RSS for posts</a></li><li class="navigation-item"><a class="internal-link rss" href="/b/the1/atom.aspx"><span></span>Atom</a></li><li id=""RssComments""" class="navigation-item"><a class="internal-link rss" href="/b/the1/rsscomments.aspx"><span></span>RSS for comments</a></li>
		</ul>
		<div class="navigation-list-footer"></div>
	</div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment search-form no-wrapper-with-spacing with-header" id="fragment-52312">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-header"><div>Search</div></div>
<div class="content-fragment-content">

<div class="field-list-header">
</div>
<fieldset class="field-list">
    <ul class="field-list">
        <li class="field-item search">
            <div id="search-allblogs-container">
                <span class="field-item-input">
                    <input id="SearchTextBox_AllBlogs" name="SearchTextBox_AllBlogs" type="text" class="searchField"
                        maxlength="64" size="45" autocomplete="off" />
                    <input id="SearchButton_AllBlogs" name="SearchButton_AllBlogs" type="button" class="search-button" />
                </span>
            </div>
            <div id="search-thisblog-container">
                <span class="field-item-input">
                    <input id="SearchTextBox_ThisBlog" name="SearchTextBox_ThisBlog" type="text" class="searchField"
                        maxlength="64" size="45" autocomplete="off" />
                    <input id="SearchButton_ThisBlog" name="SearchButton_ThisBlog" type="button" class="search-button" />
                </span>
            </div>
        </li>
    </ul>
</fieldset>
<div class="field-list-footer">
    <div id="search-switch-container">
        <span style="display: inline-block">
            <input type="radio" name="SearchTypeRadio" value="ThisBlog" id="ThisBlog" checked="checked" /><label
                for="ThisBlog" id="ThisBlogText">Search this blog</label></span>
        <span style="display: inline-block">
            <input type="radio" name="SearchTypeRadio" value="AllBlogs" id="AllBlogs" /><label
                for="AllBlogs" id="AllBlogsText">Search all blogs</label></span>
    </div>
</div>
<script type="text/javascript">
var elmSearchAll = $('#search-allblogs-container').hide();
var elmSearchThis = $('#search-thisblog-container');

// try to get the blog id, if we fail, then we aren't on a blog and just use the regular search approach       
(3405 === -1) && $('#search-switch-container').hide();

$(document).ready(function() {
    $('#ThisBlog').click(function () {
        var self = $(this);
        if (self.is(':checked')) {
            elmSearchAll.hide();
            elmSearchThis.show();
        }
    });
    
    $('#AllBlogs').click(function () {
        var self = $(this);
        if (self.is(':checked')) {
            elmSearchThis.hide();
            elmSearchAll.show();
        }
    });
});
</script>
<script src="http://i4.services.social.microsoft.com/Search/Widgets/SearchBox.jss?boxid=SearchTextBox_AllBlogs&btnid=SearchButton_AllBlogs&brand=MSDN&refinement=109&resref=&addEnglish=&rn=&rq=&watermark=&focusOnInit=false&beta=0&iroot=&overrideWatermark=false" type="text/javascript" language="javascript"></script>
<script src="http://i4.services.social.microsoft.com/Search/Widgets/SearchBox.jss?boxid=SearchTextBox_ThisBlog&btnid=SearchButton_ThisBlog&brand=MSDN&refinement=&resref=&addEnglish=&watermark=&focusOnInit=false&beta=0&iroot=&overrideWatermark=false&rn=the1%2527s%2bWebLog&rq=site:blogs.msdn.com/b/the1/" type="text/javascript" language="javascript"></script>
</div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment tag-cloud no-wrapper-with-spacing with-header" id="fragment-52313">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-header"><div>Tags</div></div>
<div class="content-fragment-content">
<div class="tag-list-header"></div><ul class="tag-list">
<li class="tag-item level-6"><a href="http://blogs.msdn.com/b/the1/archive/tags/Misc/" rel="tag">Misc</a></li>
<li class="tag-item level-4"><a href="http://blogs.msdn.com/b/the1/archive/tags/Pages/" rel="tag">Pages</a></li>
<li class="tag-item level-1"><a href="http://blogs.msdn.com/b/the1/archive/tags/Software+Development/" rel="tag">Software Development</a></li>
</ul>
<div class="tag-list-footer"></div>
</div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment blog-archive-list no-wrapper-with-spacing with-header" id="fragment-52314">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-header"><div>Archive</div></div>
<div class="content-fragment-content">

		<div class="content-list-header"></div>
		<div class="content-list-name">Archives</div>
		<ul class="content-list">
	
		<li class="content-item"><a class="internal-link view-post-archive-list" href="/b/the1/archive/2004/10.aspx">October 2004</a> (1)</li>
	
		<li class="content-item"><a class="internal-link view-post-archive-list" href="/b/the1/archive/2004/08.aspx">August 2004</a> (5)</li>
	
		<li class="content-item"><a class="internal-link view-post-archive-list" href="/b/the1/archive/2004/07.aspx">July 2004</a> (2)</li>
	
		<li class="content-item"><a class="internal-link view-post-archive-list" href="/b/the1/archive/2004/05.aspx">May 2004</a> (2)</li>
	
		<li class="content-item"><a class="internal-link view-post-archive-list" href="/b/the1/archive/2004/04.aspx">April 2004</a> (6)</li>
	
		<li class="content-item"><a class="internal-link view-post-archive-list" href="/b/the1/archive/2004/03.aspx">March 2004</a> (6)</li>
	
		</ul>
		<div class="content-list-footer"></div>
	
</div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
</div>
</div>
<div class="layout-region content" id="ctl00_content_ctl00_content">
<div class="layout-region-inner content"><div class="content-fragment blog-title full-border" id="fragment-52315">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-content">
<h1 class="title">
	    
			        
			    
	                How Would You Get the Count of an Array in C++?
			    
	</h1></div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment blog-bread-crumbs no-wrapper" id="fragment-52316">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-content">


<div class="breadcrumb-list-header"></div>
<div class="breadcrumb-list">
	<span class="breadcrumb-item"><a class="internal-link view-home" href="/">MSDN Blogs</a></span>
  
	

	
			<span class="separator"> > </span>
			<span class="breadcrumb-item">
		<a href="/b/the1/">the1's WebLog</a>
			</span>
		
	
	
			<span class="separator"> > </span>
			<span class="breadcrumb-item">
		<a href="/b/the1/archive/2004/05/07/128242.aspx">How Would You Get the Count of an Array in C++?</a>
			</span>
		

	
</div>
<div class="breadcrumb-list-footer"></div>
</div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment blog-post no-wrapper" id="fragment-52317">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-content">

<div class="full-post-header"></div>
<div class="full-post">
	<h3 class="post-name">How Would You Get the Count of an Array in C++?</h3>
	
    <div class="post-author" >
        <span class="avatar"><a href="/3405/ProfileUrlRedirect.ashx"><img src="/utility/anonymous.gif" alt="" style="border-width:0px;max-height:32px;max-width:32px;" /></a></span>
        
         <span class="profile-usercard-hover" data-profile-userid="00000000-0000-0000-0000-000000000000">
            <span class="user-name"><a class="internal-link view-user-profile" href="/3405/ProfileUrlRedirect.ashx"><span></span>the1</a></span>
       
            
        </span>
    </div>
    <div class="post-date">
        <span class="value">
            7 May 2004 5:56 PM
        </span>
    </div>
    <div class="post-attributes">
        <div class="attribute-list-header"></div>
        <ul class="attribute-list">
             <li class="attribute-item post-reply-count">
                <span class="attribute-name">Comments</span>
                <span class="attribute-value"><a href="#comments" class="internal-link view-replies"><span></span>6</a></span>
             </li>
        </ul>
        <div class="attribute-list-footer"></div>
    </div>
    <div class="post-content user-defined-markup"><P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT face=Verdana size=2></FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana>The question is simple: given a C++ array (e.g. </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">x</FONT></SPAN><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana> as in </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">int x[10]</FONT></SPAN><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana>), how would you get the <I style="mso-bidi-font-style: normal">number of elements</I> in it?<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>An obvious solution is the following macro (<I style="mso-bidi-font-style: normal">definition 1</I>):<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">#define</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> countof( array ) ( <SPAN style="COLOR: blue">sizeof</SPAN>( array )/<SPAN style="COLOR: blue">sizeof</SPAN>( array[0] ) )<o:p></o:p></SPAN></FONT></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>I cannot say this isn&#8217;t correct, because it does give the right answer when you give it an array.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>However, the same expression gives you something bogus when you supply something that is not an array.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>For example, if you have<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-size: 10.0pt"><SPAN style="mso-tab-count: 1"><FONT face=Verdana>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></SPAN></SPAN><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">int</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> * p;</SPAN><SPAN style="mso-bidi-font-size: 10.0pt"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana>then </FONT></SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">countof( p )</SPAN><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana> always give you 1 on a machine where an </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">int</FONT></SPAN><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana> pointer and an </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">int</FONT></SPAN><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana> have the same size (e.g. on a Win32 platform).<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana>This macro also wrongfully accepts any object of a class that has a member function </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">operator[]</FONT></SPAN><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana>.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>For example, suppose you write<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">class</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> IntArray<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">private</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">:<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">int</SPAN> * p;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>size_t size;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">public</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">:<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">int</SPAN> &amp; <SPAN style="COLOR: blue">operator</SPAN> [] ( size_t i );<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>} x;<o:p></o:p></FONT></SPAN></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-size: 10.0pt"><FONT face=Verdana>then </FONT></SPAN><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">sizeof</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">( x )</SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana> will be the size of the x object, not the size of the buffer pointed to by </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">x.p</FONT></SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana>.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Therefore you won&#8217;t get a correct answer by </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">countof( x )</FONT></SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana>.<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>So we conclude that definition 1 is not good because the compiler does not prevent you from misusing it.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>It fails to enforce that only an array can be passed in.<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>What is a better option?<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana>Well, if we want the compiler to ensure that the parameter to </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">countof</FONT></SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana> is always an array, we have to <I style="mso-bidi-font-style: normal">find a context where only an array is allowed</I>.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>The same context should reject any non-array expression.<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>Some beginners may try this (<I style="mso-bidi-font-style: normal">definition 2</I>):<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">template</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> &lt;<SPAN style="COLOR: blue">typename</SPAN> T, size_t N&gt;<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>size_t countof( T array[N] )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> N;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana>They figure, this template function will accept an array of </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">N</FONT></SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana> elements and return </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">N</FONT></SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana>.<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>Unfortunately, this doesn&#8217;t compile because <I style="mso-bidi-font-style: normal">C++ treats an array parameter the same as a pointer parameter</I>, i.e. the above definition is equivalent to:<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">template</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> &lt;<SPAN style="COLOR: blue">typename</SPAN> T, size_t N&gt;<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>size_t countof( T * array )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> N;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana>It now becomes obvious that the function body has no way of knowing what </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">N</FONT></SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana> is.<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>However, if a function expects an array <B style="mso-bidi-font-weight: normal">reference</B>, then the compiler does make sure that the size of the actual parameter matches the declaration.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This means we can make definition 2 work with a minor modification (<I style="mso-bidi-font-style: normal">definition 3</I>):<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">template</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> &lt;<SPAN style="COLOR: blue">typename</SPAN> T, size_t N&gt;<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>size_t countof( T (<B style="mso-bidi-font-weight: normal"><SPAN style="COLOR: red">&amp;</SPAN></B>array)[N] )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> N;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana>This </FONT></SPAN><SPAN class=CodeChar><FONT face="Courier New">countof</FONT></SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana> works very well and you cannot fool it by giving it a pointer.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>However, it is a <I style="mso-bidi-font-style: normal">function</I>, not a macro.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This means <I style="mso-bidi-font-style: normal">you cannot use it where a compile time constant is expected</I>.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>In particular, you <B style="mso-bidi-font-weight: normal">cannot</B> write something like:<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">int</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> x[10];<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">int</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> y[ 2*countof(x) ]; <SPAN style="COLOR: green">// twice as big as x<o:p></o:p></SPAN></SPAN></FONT></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>Can we do anything about it?<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana>Someone (I don&#8217;t know who it is &#8211; I just saw it in a piece of code from an unknown author) came up with a clever idea: <I style="mso-bidi-font-style: normal">moving </I></FONT></SPAN><SPAN class=CodeChar><I style="mso-bidi-font-style: normal"><FONT face="Courier New">N</FONT></I></SPAN><FONT face=Verdana><I style="mso-bidi-font-style: normal"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"> from the body of the function to the return type</SPAN></I><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"> (e.g. make the function return an array of </SPAN></FONT><SPAN class=CodeChar><FONT face="Courier New">N</FONT></SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana> elements), then we can get the value of </FONT></SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">N</SPAN><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT face=Verdana> without actually calling the function.<o:p></o:p></FONT></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>To be precise, we have to make the function return an <B style="mso-bidi-font-weight: normal">array reference</B>, as C++ does not allow you to return an array directly.<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>The implementation of this is:<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">template</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> &lt;<SPAN style="COLOR: blue">typename</SPAN> T, size_t N&gt;<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">char</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> ( &amp;_ArraySizeHelper( T (&amp;array)[N] ))[N];<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">#define</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> countof( array ) (<SPAN style="COLOR: blue">sizeof</SPAN>( _ArraySizeHelper( array ) ))<o:p></o:p></SPAN></FONT></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>Admittedly, the syntax looks awful.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Indeed, some explanation is necessary.<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2><FONT face=Verdana>First, the top-level stuff<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">char</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> ( &amp;_ArraySizeHelper( <SPAN style="COLOR: red">...</SPAN> ))[N];<o:p></o:p></SPAN></FONT></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face=Verdana>says &#8220;</FONT><SPAN class=CodeChar><FONT face="Courier New">_ArraySizeHelper</FONT></SPAN><FONT face=Verdana> is a function that returns a reference (note the </FONT><SPAN class=CodeChar><FONT face="Courier New">&amp;</FONT></SPAN><FONT face=Verdana>) to a </FONT><SPAN class=CodeChar><FONT face="Courier New">char</FONT></SPAN><FONT face=Verdana> array of </FONT><SPAN class=CodeChar><FONT face="Courier New">N</FONT></SPAN><FONT face=Verdana> elements&#8221;.</FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Verdana size=2>Next, the function parameter is</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt"><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"><FONT size=2>T (&amp;array)[N]<o:p></o:p></FONT></SPAN></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face=Verdana>which is a reference to a </FONT><SPAN class=CodeChar><FONT face="Courier New">T</FONT></SPAN><FONT face=Verdana> array of </FONT><SPAN class=CodeChar><FONT face="Courier New">N</FONT></SPAN><FONT face=Verdana> elements.</FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face=Verdana>Finally, </FONT><SPAN class=CodeChar><FONT face="Courier New">countof</FONT></SPAN><FONT face=Verdana> is defined as the size of the result of the function </FONT><SPAN class=CodeChar><FONT face="Courier New">_ArraySizeHelper</FONT></SPAN><FONT face=Verdana>.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Note we don&#8217;t even need to define </FONT><SPAN class=CodeChar><FONT face="Courier New">_ArraySizeHelper()</FONT></SPAN><FONT face=Verdana>, -- a declaration is enough.</FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Verdana size=2>With this new definition,</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #ffff99; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.5in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div; mso-border-alt: solid windowtext .5pt">
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">int</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> x[10];<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 0in; BACKGROUND: #ffff99; PADDING-BOTTOM: 0in; MARGIN: 0in 0in 0pt; BORDER-LEFT: medium none; PADDING-TOP: 0in; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; mso-layout-grid-align: none"><FONT size=2><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">int</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt"> y[ 2*countof(x) ]; <SPAN style="COLOR: green">// twice as big as x<o:p></o:p></SPAN></SPAN></FONT></P></DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 10.0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Verdana size=2>becomes valid, just as we desire.</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face=Verdana>Am I happy now?<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Well, I think this definition is definitely better than the others we have visited, but it is still not quite what I want.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>For one thing, <I style="mso-bidi-font-style: normal">it doesn&#8217;t work with types defined inside a function</I>.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>That&#8217;s because the template function </FONT><SPAN class=CodeChar><FONT face="Courier New">_ArraySizeHelper</FONT></SPAN><FONT face=Verdana> expects a type that is accessible in the global scope.</FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Verdana size=2>I don&#8217;t have a better solution.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>If you know one, please let me know.</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face=Verdana>BTW, how does one solve the same problem for C#?<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>It&#8217;s trivial there.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>You just say &#8220;</FONT><SPAN class=CodeChar><FONT face="Courier New">x.length()</FONT></SPAN><FONT face=Verdana>&#8221; (I forgot the actual syntax, but you should get the idea).</FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face=Verdana size=2>&nbsp;</FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face=Verdana size=2>One thing to point out is that, in C# the count of an array is <B style="mso-bidi-font-weight: normal">not</B> in its type.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>You decide how many elements are there when you create the array at run time.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Therefore, don&#8217;t even try to derive this information at compile time.</FONT></P><div style="clear:both;"></div></div>
    <div class="post-attachment-viewer">
		
    </div>
    <div class="post-actions">
        <div class="navigation-list-header"></div>
        <ul class="navigation-list">
            <!---->
            <li class="navigation-item"><a class="internal-link view-replies" href="/b/the1/archive/2004/05/07/128242.aspx#comments"><span></span>6 Comments</a></li>
            
            
        </ul>
        <div class="navigation-list-footer"></div>
    </div>
    <div class="post-tags"><div id="ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_Container" style="display: none;"><div class="tags-editor"><textarea id="ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_Tags" style="width: 97%; height: 100%;" rows="2" cols="30"></textarea><div style="white-space: nowrap; padding-top: 4px;"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td align="left"><input type="button" onclick="Telligent_Modal.Open('\/utility\/TagSelector.aspx?TagEditor=ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_TagEditor',400,300,null);;return false;" value="Select Tags..." /></td><td align="right"><input type="button" onclick="ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01.Save(); return false;" value="Save" /><input type="button" onclick="ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01.Close(); return false;" value="Cancel" /></td></tr></table></div></div></div><span id="ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl02"><a href="http://blogs.msdn.com/b/the1/archive/tags/Software+Development/" rel="tag">Software Development</a></span><input type="hidden" name="ctl00$content$ctl00$w_52317$_af8d15$ctl00$ctl15$ctl02" id="ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl02_State" value="nochange" /></div>
</div>
<div class="full-post-footer"></div></div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment social-media-sharing no-wrapper" id="fragment-52318">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-content">

<script src="http://i1.blogs.msdn.com/rrcontent/47499858c4077d6e043f7add14000981-e99ec8f3b45f97b38095df2708dc5898-RequestReducedScript.js" type="text/javascript" ></script>
<div class="ShareThisMainPanel">
	<div id="ctl00_content_ctl00_w_52318__af8d15_ctl00_f35306c2_a3e5_413c_9660_c352ada581dd" class="ShareThis_ChildRootPanel" onmouseover="ShareThisChildRootPanelOnmouseOver(this.id);" onmouseout="ShareThisChildRootPanelOnmouseOut(this.id);">
		<div id="ctl00_content_ctl00_w_52318__af8d15_ctl00_ShareThisBtnCollPanel_482cceef7b4f4e558596cd55ee011e50" class="tierOnePanel">
			<div class="buttonPanel">
				<a title="Share on Facebook" class="iconsOnPanel" href="http://www.facebook.com/sharer.php?u=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;t=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on Facebook" src="/CustomWidgets/SocialMediaSharingUC/Resources/facebook.gif" style="border-width:0px;" /></a>
			</div><div class="buttonPanel">
				<a title="Share on Twitter" class="iconsOnPanel" href="http://twitter.com/home?status=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f : http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx" target="_blank"><img title="Share on Twitter" src="/CustomWidgets/SocialMediaSharingUC/Resources/twitter.gif" style="border-width:0px;" /></a>
			</div><div class="buttonPanel">
				<a title="Share on Digg" class="iconsOnPanel" href="http://digg.com/submit?url=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;title=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on Digg" src="/CustomWidgets/SocialMediaSharingUC/Resources/digg.gif" style="border-width:0px;" /></a>
			</div><div class="buttonPanel">
				<a title="Share on del.icio.us" class="iconsOnPanel" href="http://del.icio.us/post?url=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;title=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on del.icio.us" src="/CustomWidgets/SocialMediaSharingUC/Resources/delicious.gif" style="border-width:0px;" /></a>
			</div>
		</div><div id="ctl00_content_ctl00_w_52318__af8d15_ctl00_ShareThisBtnCollPanel_096187f398394954a2fee982498e88eb" class="tierTwoPanel" onclick="TierTwoPanelOnclick(this.id);" onkeypress="if (event.keyCode == 13) TierTwoPanelOnclick(this.id);" onmouseover="TierTwoPanelOnmouseOver(this.id);" onmouseout="TierTwoPanelOnmouseOut(this.id);">
			<div id="ctl00_content_ctl00_w_52318__af8d15_ctl00_ShareThisBtnCollPanel_4e15e02d75724192a7e5f7b1313a7a16" class="tierTwoRowPanel">
				<div class="buttonPanel">
					<a title="Share on Reddit" class="iconsOnPanel" href="http://www.reddit.com/submit?url=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;title=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on Reddit" src="/CustomWidgets/SocialMediaSharingUC/Resources/reddit.gif" style="border-width:0px;" /></a>
				</div><div class="buttonPanel">
					<a title="Share on LinkedIn" class="iconsOnPanel" href="http://www.linkedin.com/shareArticle?mini=true&amp;ro=true&amp;url=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;title=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f&amp;summary=&amp;source=Microsoft&amp;armin=armin" target="_blank"><img title="Share on LinkedIn" src="/CustomWidgets/SocialMediaSharingUC/Resources/linkedin.gif" style="border-width:0px;" /></a>
				</div><div class="buttonPanel">
					<a title="Share on Slashdot" class="iconsOnPanel" href="http://slashdot.org/bookmark.pl?url=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;title=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on Slashdot" src="/CustomWidgets/SocialMediaSharingUC/Resources/slashdot.gif" style="border-width:0px;" /></a>
				</div><div class="buttonPanel">
					<a title="Share on MySpace" class="iconsOnPanel" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;t=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on MySpace" src="/CustomWidgets/SocialMediaSharingUC/Resources/myspace.gif" style="border-width:0px;" /></a>
				</div>
			</div><div id="ctl00_content_ctl00_w_52318__af8d15_ctl00_ShareThisBtnCollPanel_ee41a3d5a1414bdfbf64e806036a3de8" class="tierTwoRowPanel">
				<div class="buttonPanel">
					<a title="Share on Technorati" class="iconsOnPanel" href="http://technorati.com/faves/?add=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx" target="_blank"><img title="Share on Technorati" src="/CustomWidgets/SocialMediaSharingUC/Resources/technorati.gif" style="border-width:0px;" /></a>
				</div><div class="buttonPanel">
					<a title="Share on FriendFeed" class="iconsOnPanel" href="http://friendfeed.com/?url=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;title=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on FriendFeed" src="/CustomWidgets/SocialMediaSharingUC/Resources/friendfeed.gif" style="border-width:0px;" /></a>
				</div><div class="buttonPanel">
					<a title="Share on Messenger" class="iconsOnPanel" href="http://profile.live.com/badge?url=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;title=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on Messenger" src="/CustomWidgets/SocialMediaSharingUC/Resources/messenger.png" style="border-width:0px;" /></a>
				</div><div class="buttonPanel">
					<a title="Share on StumbleUpon" class="iconsOnPanel" href="http://www.stumbleupon.com/submit?url=http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx&amp;title=How+Would+You+Get+the+Count+of+an+Array+in+C%2b%2b%3f" target="_blank"><img title="Share on StumbleUpon" src="/CustomWidgets/SocialMediaSharingUC/Resources/stumbleupon.gif" style="border-width:0px;" /></a>
				</div>
			</div>
		</div>
	</div><div id="ctl00_content_ctl00_w_52318__af8d15_ctl00_ShowMoreLessButtonsPanel_ca38dec6_4e1b_42a5_a053_143037d8acac" tabindex="1" class="ShowMoreLessButtonsPanel" onclick="ShowMoreLessButtonsPanelOnClick(this.id);" onkeypress="if (event.keyCode == 13) ShowMoreLessButtonsPanelOnClick(this.id);" onmouseover="ShowMoreLessButtonsPanelOnmouseOver(this.id);" onmouseout="ShowMoreLessButtonsPanelOnmouseOut(this.id);">
		<a class="buttonMoreLess" id="btn_more"><img title="More" src="/CustomWidgets/SocialMediaSharingUC/Resources/more.gif" src="" style="border-width:0px;" /></a><a class="buttonMoreLess" id="btn_less"><img title="Less" src="/CustomWidgets/SocialMediaSharingUC/Resources/less.gif" src="" style="border-width:0px;" /></a>
	</div>
</div><div class="ShareClearFloatsPanel">

</div></div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment blog-feedback-list no-wrapper with-header" id="fragment-52319">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-header"><div>Blog - Comment List MSDN TechNet</div></div>
<div class="content-fragment-content">

<script src="http://i1.blogs.msdn.com/rrcontent/c6cf9e2cff3f0bfc0a1a8c20bf243544-5882c0bb1c3252f4238afcfee921f6f5-RequestReducedScript.js" type="text/javascript" ></script>
<script type="text/javascript">
    // <![CDATA[
    (function ($) {
        $.extend(jQuery.tmpl.tag, {
            "for": {
                _default: { $2: "var i=1;i<=1;i++" },
                open: 'for ($2){',
                close: '};'
            }
        });
    })(jQuery);

    function findYPos(obj) {
        var curtop = 0;
        if (obj.offsetParent) {
            do {
                curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
            return [curtop];
        }
    }

    var endpoint = '/b/the1/listComments.aspx';
    var deleteendpoint = '/Utility/ContentFragments/Blogs/FeedbackListAjax.asmx';  
    $(document).ready(function () {
        if (window.location.hash) {
            var commentHash = parseInt(window.location.hash.substring(1, window.location.hash.length));
            if (!isNaN(commentHash)) {
                loadComments(0, commentHash, true);
                return;
            }
        }

        loadComments(0, 0, true);
    });

    function loadComments(page, anchorId, isFirstLoad) {
        $.ajax({
            type: 'POST',
            async: false,
            contentType: 'application/json',
            dataType: 'json',
            url: endpoint + '?blogId=3405&postId=128242&page=' + page + '&commentId=' + anchorId + '&pageSize=1000&firstLoad=' + isFirstLoad + "&time=" + new Date().getTime(),
            success: function (data) {
                var pager = $('#pagerContainer');

                $('#commentList').html('');
                $('#commentList').html($('#commentTemplate').tmpl(data.Comments));
                $('#pagerContainer').html($('#pagerTemplate').tmpl(data));

                $('.pagingLink').click(function (e) {
                    e.preventDefault();
                    loadComments($(this).data('page'), 0, false);
                    window.scroll(0, findYPos(document.getElementById('commentList')) - 50);
                    return false;
                });

                $('.pagingLink').removeClass('selected');
                $('#pager' + data.CurrentPage).addClass('selected');

	            
            }
        });
    }
    // ]]>
</script>


<a name="comments"></a>
<div class="content-list-header"></div>
<div class="content-list-name">
    
            <a class="internal-link rss" href="/b/the1/rsscomments.aspx?WeblogPostID=128242"><span></span>Comments</a>
        
</div>



<ul id="commentList" class="content-list">
      <li class="content-item">Loading...</li>
</ul>
<div id="pagerContainer" class="pager"></div>
<div class="content-list-footer"></div>

<script id="commentTemplate" type="text/html">
    {{if Author}}
    <li id="commentItem${Id}" class="content-item">
        <div class="full-post-outer fiji-full-post-outer"><div class="full-post-header"><div class="r fiji-r"></div></div>
        <div class="full-post"><div class="full-post-inner fiji-full-post-inner">
            <div class="post-author">
                <span class="avatar">
                    {{if !Author.IsAnonymous}}
                    <a href="${Author.ProfileUrl}">
                        <img src="${Author.AvatarUrl}" style="border-width:0;max-height:32px;max-width:32px;"/>
                    </a>
                    {{else}}
                    <img src="${Author.AvatarUrl}" style="border-width:0;max-height:32px;max-width:32px;"/>
                    {{/if}}
                </span>
                <span class="profile-usercard-hover" data-profile-userid="${Author.ProfileId}">
                    <span class="user-name">
                        {{if !Author.IsAnonymous}}
                        <a href="${Author.ProfileUrl}">
                            ${Author.DisplayName}
                        </a>
                        {{else}}
                        ${Author.DisplayName}
                        {{/if}}
                    </span>
                </span>
            </div>
            <div class="post-date">
                <span class="value">${PublishedDate}</span>
            </div>
            <a name="${Id}" style="padding-left:5px;" href="#${Id}">#</a>
            <div class="post-content user-defined-markup">
                {{html Body}}
            </div>
            <div class="post-actions">
                
            </div>
        </div>
        {{if !Author.IsAnonymous && Author.Id == 3405}}
        <div class="full-post-footer user-is-author">
        {{else}}
        <div class="full-post-footer">
        {{/if}}
            <div class="r wireframe-r"></div>
        </div>
    </li>
    {{/if}}
</script>


<script id="pagerTemplate" type="text/html">
    {{if TotalPages}}     
        {{if TotalPages > 1}}     
            <span class="summary">Page 1 of 3 (39 items)</span>            
        
             {{for(i=1;i<=TotalPages;i++)}}            
                <a id="pager${i}" data-page="${i}" href="javascript:void(0);" class="pagingLink">
                    <span>${i}</span>
                </a>
                <span class="separator"></span>
            {{/for }}
        {{else}}  
        {{/if}}
    {{else}}      
    {{/if}}
</script></div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
<div class="content-fragment captcha-blog-post-comment-form no-wrapper" id="fragment-52320">
<div class="content-fragment-inner msdn-content-fragment-inner"><div class="content-fragment-top msdn-content-fragment-top"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div><div class="content-fragment-content">
<input type="hidden" name="ctl00$content$ctl00$w_52320$_af8d15$ctl00$ctl00$postCommentUrl" id="ctl00_content_ctl00_w_52320__af8d15_ctl00_ctl00_postCommentUrl" />

    
    </div>
<div class="content-fragment-footer"></div>
<div class="content-fragment-bottom msdn-content-fragment-bottom"><div class="r1 msdn-r1"></div><div class="r2 msdn-r2"></div><div class="r3 msdn-r3"></div><div class="r4 msdn-r4"></div></div></div></div>
</div>
</div>
</div>
<div class="layout-footer"></div>
</div></div>

			<div class="footer-fragments-header"></div>
<div class="footer-fragments"><div class="footer-fragment copyright-info" id="footer-fragment-1402503690">

<ul class="footer-fragment-links">
    <li class="message copyright">© 2014 Microsoft Corporation.</li>
	<li class="message termsOfService"><a href="http://msdn.microsoft.com/cc300389">Terms of Use</a> </li>
    <li class="message trademarks"><a href="http://www.microsoft.com/library/toolbar/3.0/trademarks/en-us.mspx">Trademarks</a> </li>
    <li class="message privacy"><a href="http://go.microsoft.com/fwlink/?LinkId=248681">Privacy &amp; Cookies</a> </li>
    <li class="message abuse">
    
            <a id="ctl00_footer_fragment_1402503690__af8d15_ctl00_ctl00_ctl01_lnkAbuse" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$footer_fragment_1402503690$_af8d15$ctl00$ctl00$ctl01$lnkAbuse&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))">Report Abuse</a>
        
    </li>
    
    <li class="message version">5.6.426.415</li>
</ul></div><div class="footer-fragment omniture-footer-fragment" id="footer-fragment-1402503691">


<script src="http://i1.blogs.msdn.com/rrcontent/2569210a296af7a76a1f0a41cafcfd42-2e0c141b75ad92888490f6154505d4c2-RequestReducedScript.js" type="text/javascript" ></script>        <noscript><a href="http://www.omniture.com" title="Web Analytics"><img
        src="http://msstomsdnblogs.112.2O7.net/b/ss/msstomsdnblogs/1/H.20.2--NS/0"
        height="1" width="1" border="0" alt="" /></a></noscript>

</div><div class="footer-fragment app-insights-footer-fragment" id="footer-fragment-1402503692">

        <script type="text/javascript" language="javascript">
            $(document).ready(function () {
                window.appInsights = { queue: [], start: function (n) { function r(n, t) { n[t] = function () { var i = arguments; n.queue.push(function () { n[t].apply(n, i) }) } } var t, i; this.applicationInsightsId = n; this.accountId = null; this.appUserId = null; r(this, "logEvent"); r(this, "logPageView"); t = document.createElement("script"); t.type = "text/javascript"; t.src = "//az416426.vo.msecnd.net/scripts/ai.js"; t.async = !0; i = document.getElementsByTagName("script")[0]; i.parentNode.insertBefore(t, i) } };
                window.appInsights.start("b4d65b72-ce61-486e-b07c-969cef6675f6");
                window.appInsights.logPageView();
            });
        </script>
    </div></div>
<div class="footer-fragments-footer"></div>
		
<script type="text/javascript">
// <![CDATA[
ctl00_content_ctl00 = new ContentFragmentPageCustomCallback('ctl00_content_ctl00',new Function('mode','parameters','callback','errorCallback','context','ctl00_content_ctl00_ctl00._doCallback(mode+\':\'+parameters,callback,context,errorCallback);'));
// ]]>
</script>
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx"
dc:identifier="http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx"
dc:title="How Would You Get the Count of an Array in C++?"
trackback:ping="http://blogs.msdn.com/b/the1/trackback.ashx?WeblogPostID=128242" />
</rdf:RDF>
-->
<script type="text/javascript">
// <![CDATA[
Telligent_Modal.Configure('\/utility\/loading.htm',['modal'],['modal-title','modal-title-2','modal-title-3','modal-title-4'],['modal-close'],['modal-content','modal-content-2'],['modal-footer','modal-footer-2','modal-footer-3'],['modal-resize'],['modal-mask'],10000,false,true,true);
// ]]>
</script><script type="text/javascript">
// <![CDATA[
window.ctl00_content_ctl00_ctl00 = new Telligent_CallbackManager('ctl00_content_ctl00_ctl00','ctl00$content$ctl00$ctl00','aspnetForm');
// ]]>
</script><script type="text/javascript">
// <![CDATA[
$('#ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_Container input[value="Save"]').attr('onclick','').removeAttr('onclick').click( function(){ try { var tagText = $('#ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_Tags').val(); if (!tagText) return false;var tagList = tagText.replace(';',',').split(','); var isValid = true; for (var i=0,l=tagList.length;i<l;i++) {isValid = /^[ -~]{0,100}$/ig.test(tagList[i]); if (!isValid) { alert(tagList[i] + ' : is not valide'); return false; } }ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01.Save();}catch(ex){ } return false; });
// ]]>
</script>
<script type="text/javascript">
// <![CDATA[
window.ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01 = new Telligent_InlineEditor('ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01','ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_Container',new Function('id', 'p', 'ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_InlineTagEditor.SetInlineEditorPanelAndParameter(id,p);'),new Function('return ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_InlineTagEditor.GetContent();'),new Function('c', 'ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_InlineTagEditor.SetContent(c);'),null,new Function('ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_InlineTagEditor.Focus();'),new Function('w', 'h', 'ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_InlineTagEditor.Resize(w,h);'),300,90);
// ]]>
</script><script type="text/javascript">
// <![CDATA[
var ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_TagEditor = new TagEditor('ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_TagEditor',[['Misc','Misc'],['Pages','Pages'],['Software Development','Software Development']],'ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_Tags');
// ]]>
</script><script type="text/javascript">
// <![CDATA[
var ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_InlineTagEditor = new InlineTagEditor('ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_InlineTagEditor','ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01','ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_Container','ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01_Tags');
// ]]>
</script><script type="text/javascript">
// <![CDATA[
window.ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl02 = new Telligent_InlineEditorPanel('ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl02','ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl02','ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl02_State','ctl00_content_ctl00_w_52317__af8d15_ctl00_ctl15_ctl01',false,null,null,null);
// ]]>
</script></form>
       
    <script type="text/javascript">
        $(window).load(function () {
            $.getScript('http://widgets.membership.s-msft.com/v1/loader.js?brand=msdn&lang=en-US', function () {
            });
        });
    </script>
    
	
        <script type="text/javascript">$('div.breadcrumb-list span:last a').addClass('last');</script></body>
</html>
